package com.conversationboard.controller;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.conversationboard.cache.UserCache;
import com.conversationboard.config.Configuration;
import com.conversationboard.model.Bookmarks;
import com.conversationboard.model.User;

@WebServlet(name = "DeleteAllBookmarksControllerServlet", urlPatterns = "/DeleteAllBookmarksControllerServlet")
public class DeleteAllBookmarksControllerServlet extends HttpServlet {

	private static final long serialVersionUID = -1739595953529837841L;


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		try {

			User user = User.get(request.getUserPrincipal());

			if (!SecurityChecks.passes(request, user, this)) {
				return;
			}

			Bookmarks.deleteAll(user.getUserId());
			UserCache.getInstance().removeUser(user.getLoginId());

			response.sendRedirect(Configuration.getInstance().getRoot() + "/BookmarksControllerServlet");

		} catch (SQLException e) {
			throw new ServletException(e);
		}

	}

}
